package com.shangxian.giveithome.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
public class httpPostr extends SenInfoCheckUtil {

    public static String
            AppId = "wx779c8e01d6657934";

    public static String Secret = "ac3944ae3083decc1ca4f17dfad179ec";

    public static String getAppId() {
        return AppId;
    }

    public static void setAppId(String appId) {
        AppId = appId;
    }

    public static String getSecret() {
        return Secret;
    }

    public static void setSecret(String secret) {
        Secret = secret;
    }


    /**
     * 用于模拟HTTP请求中GET/POST方式
     *
     * @author landa
     */
    public static class HttpUtils {

        /**
         * 发送GET请求
         *
         * @param url 目的地址
         * @return 远程响应结果
         */
        public static String sendGet(String url) {
            String result = "";
            BufferedReader in = null;// 读取响应输入流
            java.net.URL connURL = null;
            try {
                connURL = new java.net.URL(url);

                // 打开URL连接
                java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL
                        .openConnection();
                // 设置通用属性
                httpConn.setRequestProperty("Accept", "*/*");
                httpConn.setRequestProperty("Connection", "Keep-Alive");
                httpConn.setRequestProperty("User-Agent",
                        "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
                // 建立实际的连接
                httpConn.connect();
                // 响应头部获取
                Map<String, List<String>> headers = httpConn.getHeaderFields();
                // 遍历所有的响应头字段
                for (String key : headers.keySet()) {
                    System.out.println(key + "\t：\t" + headers.get(key));
                }
                // 定义BufferedReader输入流来读取URL的响应,并设置编码方式
                in = new BufferedReader(new InputStreamReader(httpConn
                        .getInputStream(), "UTF-8"));
                String line;
                // 读取返回的内容
                while ((line = in.readLine()) != null) {
                    result += line;
                }
                System.out.println(result);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                return result;
            }
        }

        /**
         * 主函数，测试请求
         *
         * @param args
         */
        public static void main(String[] args) {
            String s = sendGet("https:api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + getAppId() + "&secret=" + getSecret());
            System.out.println(s);

            String access_token = "40__WHh3n3H9PYPrzpr4UJxsTk4RqccYqzA4Q_ff00Bxf3trzWupOrHy3hKfM2li3l6GTWA3Q8KJRIXMkAggebaO7l--gJ1X1UkbPsCKtgIFWhbqpzVe5STvdEVj_H8Pr5geSgEnvQPoUjt7j0dARHdAGAQHX";


        }
    }
}






